<HTML>
<HEAD>
<TITLE>JavaScript Source Code 3000:  Cookies:  Name - Visits - Message</TITLE>
<META HTTP-EQUIV="JavaScript Source Code 3000" CONTENT = "no-cache">
<META NAME="date" CONTENT="2000-09-09">
<META NAME="channel" CONTENT="Web Developer">
<META NAME="author" CONTENT="Bill Dortch">
<META NAME="description" CONTENT="This cookie records the visitor's name, how many visits, and displays a message depending on how many visits have been recorded.">

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) 
break; 
}
return null;
}
function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (2 < argc) ? argv[2] : null;
var path = (3 < argc) ? argv[3] : null;
var domain = (4 < argc) ? argv[4] : null;
var secure = (5 < argc) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}
function DisplayInfo() {
var expdate = new Date();
var visit;
expdate.setTime(expdate.getTime() +  (24 * 60 * 60 * 1000 * 365)); 
if(!(visit = GetCookie("visit"))) 
visit = 0;
visit++;
SetCookie("visit", visit, expdate, "/", null, false);
var message;
if(visit == 1) 
message="         Welcome to my page!";
if(visit== 2) 
message="           I see you came back !";
if(visit == 3) 
message="               Oh, it's you again!";
if(visit == 4)
message="            You must be curious!"; 
if(visit == 5) 
message="      You're practically a regular!";
if(visit == 6) 
message="              You need a hobby!";
if(visit == 7)
message="             Nothing better to do?"; 
if(visit == 8) 
message="            Don't you ever sleep?";
if(visit == 9)
message="                      Get a life!!!"; 
if(visit >= 10) 
message="  Rent is due on the 1st of the month!";
  alert("\n"+"Your browser has visited this page               \n"
            +"                              "+visit+"\n"
            +"                          time(s)."+"\n"+"\n"
            +message);
}
function ResetCounts() {
var expdate = new Date();
expdate.setTime(expdate.getTime() +  (24 * 60 * 60 * 1000 * 365)); 
visit = 0;
SetCookie("visit", visit, expdate , "/", null, false);
history.go(0);
}
// End -->
</SCRIPT>
</HEAD>

<BODY BGCOLOR=#ffffff vlink=#0000ff onLoad="DisplayInfo()">

<BR>
<center>
<table width="600" cellpadding="0" cellspacing="10">
<tr>
<td width="468" align="center">

	
</td>
<td width="120" align="center">

	
</td>
</tr>
</table>
<BR>
<BR>
<BASEFONT SIZE=3>
  <FONT SIZE=6>
<B><FONT SIZE="+2" FACE="Helvetica,Arial" ALIGN=RIGHT COLOR="#0000FF">
<b><A HREF="../index.htm" /" TARGET="_top">
Home</A> </b><img src="../img/arrow.gif" /img/arrow.gif" height=13 width=7 border=0 alt="}"> <b><A HREF="index.htm" /cookies/"><font color="#FF0000">Cookies</font></A> </b>
<img src="../img/arrow.gif" /img/arrow.gif" height=13 width=7 border=0 alt="}"> <FONT COLOR="#006666">Name - Visits - Message</FONT></b></FONT><BR>
</B><BR>
  </FONT>
<table BORDER=0 WIDTH=486 CELLPADDING=3 CELLSPACING=0>
<tr><td><font FACE="helvetica,arial,geneva">
<br>
<br>
<!-- Description --><!--content_start-->
This cookie records the visitor's name, how many visits, and displays a message depending on how many visits have been recorded.
<br>
<hr>
</td></tr>
</table>
<!-- Demonstration -->
<BODY>
<CENTER>
<FORM>
<INPUT NAME="update" TYPE="BUTTON" VALUE="Revisit  Page" OnClick="history.go(0)">
<INPUT NAME="reset" TYPE="BUTTON" VALUE="Reset Counter" OnClick="ResetCounts()">
</FORM>
</CENTER>
<P>
<P>
<a name="source">
<table BORDER=0 WIDTH=486 CELLPADDING=3 CELLSPACING=0>
<tr><td BGCOLOR=yellow><font FACE="helvetica,arial,geneva"><b>JavaScript Source Code 3000:  Cookie:  Name - Visits - Last Visit</b>
<p>Simply click inside the window below, use your cursor to highlight the script, and copy (type Control-c or Apple-c) the script into a new file in your text editor (such as Note Pad or Simple Text) and save (Control-s or Apple-s).  The script is yours!!!<br><br></font></td></tr>
<tr><td BGCOLOR=yellow ALIGN=CENTER>
<form NAME="copy">

<DIV align="center">
<input type=button value="Highlight All" onClick="javascript:this.form.txt.focus();this.form.txt.select();">&nbsp;&nbsp;&nbsp;&nbsp;
<INPUT TYPE="text" NAME="total" VALUE="Script Size:  3.32 KB  " size="24">
</DIV>

<textarea NAME="txt" ROWS=20 COLS=75 WRAP=VIRTUAL>

&lt;!-- THREE STEPS TO INSTALL COOKIE:  NAME - VISITS - LAST VISIT:

   1.  Put the designated script into the HEAD of your HTML document
   2.  Add the onLoad event handler into the BODY tag
   3.  Copy the last script into the BODY of your HTML document  --&gt;

&lt;!-- STEP ONE: Copy this code into the HEAD of your HTML document  --&gt;
		  
&lt;HEAD&gt;

&lt;SCRIPT LANGUAGE="JavaScript"&gt;
&lt;!-- Original:  Bill Dortch, hIdaho Design (bdortch@netw.com)

&lt;! &gt;
&lt;! &gt;

&lt;!-- Begin 
function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i &lt; clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) 
break; 
}
return null;
}
function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (2 &lt; argc) ? argv[2] : null;
var path = (3 &lt; argc) ? argv[3] : null;
var domain = (4 &lt; argc) ? argv[4] : null;
var secure = (5 &lt; argc) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}
function DisplayInfo() {
var expdate = new Date();
var visit;
expdate.setTime(expdate.getTime() +  (24 * 60 * 60 * 1000 * 365)); 
if(!(visit = GetCookie("visit"))) 
visit = 0;
visit++;
SetCookie("visit", visit, expdate, "/", null, false);
var message;
if(visit == 1) 
message="         Welcome to my page!";
if(visit== 2) 
message="           I see you came back !";
if(visit == 3) 
message="               Oh, it's you again!";
if(visit == 4)
message="            You must be curious!"; 
if(visit == 5) 
message="      You're practically a regular!";
if(visit == 6) 
message="              You need a hobby!";
if(visit == 7)
message="             Nothing better to do?"; 
if(visit == 8) 
message="            Don't you ever sleep?";
if(visit == 9)
message="                      Get a life!!!"; 
if(visit &gt;= 10) 
message="  Rent is due on the 1st of the month!";
  alert("\n"+"Your browser has visited this page               \n"
            +"                              "+visit+"\n"
            +"                          time(s)."+"\n"+"\n"
            +message);
}
function ResetCounts() {
var expdate = new Date();
expdate.setTime(expdate.getTime() +  (24 * 60 * 60 * 1000 * 365)); 
visit = 0;
SetCookie("visit", visit, expdate , "/", null, false);
history.go(0);
}
// End --&gt;
&lt;/Script&gt;

&lt;!-- STEP TWO: Add the onLoad event handler into the BODY tag  --&gt; 

&lt;BODY onload="DisplayInfo()"&gt;

&lt;!-- STEP THREE: Copy this code into the BODY of your HTML document  --&gt; 

&lt;FORM&gt;
&lt;CENTER&gt;
&lt;INPUT NAME="update" TYPE="BUTTON" VALUE="Revisit  Page" OnClick="history.go(0)"&gt;
&lt;INPUT NAME="reset" TYPE="BUTTON" VALUE="Reset Counter" OnClick="ResetCounts()"&gt;
&lt;/CENTER&gt;
&lt;/FORM&gt;

 

&lt;!-- Script Size:  3.32 KB  --&gt;
</textarea><br><font FACE="helvetica,arial,geneva"></font></td></tr>

</table>
</form>
</FONT>
</CENTER>


</center>
</body></html>